<template>
    <div class="app-detail">
        <el-card class="box-card">
            <div class="container-header">
                <div class="hign-line"></div>
                <div class="header-left">
                    {{$t('inventoryManagement.baseInfo')}}
                </div>
            </div>
            <el-form :model="viewModel" ref="additonForm" v-show="showSearch" label-width="98px">
                <el-row :gutter="24" class="mb8">
                    <el-col :span="6">
                        <el-form-item :label="$t('inventoryManagement.inspectionBatchNo')" prop="lichn">
                            <el-input v-model="viewModel.inspectionLotMark" clearable disabled size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.sapBatch')" prop="lot">
                            <el-input v-model="viewModel.lot" clearable disabled size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="6">
                        <el-form-item label="MSL等级" prop="materialMsl">
                            <el-input v-model="viewModel.materialMsl" disabled clearable size="small" />
                        </el-form-item>
                    </el-col> -->
                    <el-col :span="6">
                        <el-form-item :label="$t('inventoryManagement.materialName')" prop="materialName">
                            <el-input v-model="viewModel.materialName" clearable disabled size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item :label="$t('inventoryManagement.materialNo')" prop="materialCode">
                            <el-input v-model="viewModel.materialCode" clearable disabled size="small" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item :label="$t('inventoryManagement.maturity')" prop="maturity">
                            <el-input v-model="viewModel.maturity" disabled clearable size="small" />
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="6">
                        <el-form-item label="【SAP】成熟度" prop="sapMaturity">
                            <el-input v-model="viewModel.sapMaturity" disabled size="small" />
                        </el-form-item>
                    </el-col> -->

                    <el-col :span="6">
                        <el-form-item :label="$t('inventoryManagement.supplierNo')" prop="supplierCode">
                            <el-input v-model="viewModel.supplierCode" disabled clearable size="small" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item :label="$t('inventoryManagement.supplierName')" prop="supplierName">
                            <el-input v-model="viewModel.supplierName" disabled clearable size="small" />
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="6">
                        <el-form-item label="规格型号" prop="specificationsModels">
                            <el-input v-model="viewModel.specificationsModels" clearable disabled size="small" />
                        </el-form-item>
                    </el-col> -->
                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.oldBatchQuantity')" prop="batchAmount">
                            <el-input disabled v-model="viewModel.batchAmount" clearable size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.oldUnit')" prop="mengeneinh">
                            <el-input v-model="viewModel.mengeneinh" clearable disabled size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.isInspectionExemption')" prop="exempted">
                            <el-select v-model="viewModel.exempted" style="width:100%;" clearable disabled size="small">
                                <el-option key="0" :label="$t('public.no')" value="0" />
                                <el-option key="1" :label="$t('public.yes')" value="1" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.factory')" prop="factoryName">
                            <el-input v-model="viewModel.factoryName" disabled clearable size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.reversionBatchQuantity')" prop="amendBatch">
                            <el-input v-model="viewModel.amendBatch" disabled clearable size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.reversionUnit')" prop="amendMeng">
                            <el-input v-model="viewModel.amendMeng" disabled clearable size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="6">
                        <el-form-item label="检验标准版本号" prop="version">
                            <el-input v-model="viewModel.version" disabled clearable size="small" />
                        </el-form-item>
                    </el-col>
                    <!--                    <el-col :span="6">
                        <el-form-item label="卷号" prop="reelNumber">
                            <el-input v-model="viewModel.reelNumber" clearable size="small" />
                        </el-form-item>
                    </el-col>-->
                    <!--                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.outerPackaging')" prop="outerPacking">
                            <el-select v-model="viewModel.outerPacking" :placeholder="$t('public.select_holder',{select_holder: $t('inspectionManagement.outerPackaging')})" style="width:100%;" clearable size="small">
                                <el-option key="0" label="OK" value="0" />
                                <el-option key="1" label="NG" value="1" />
                            </el-select>
                        </el-form-item>
                    </el-col>-->
                    <!-- <el-col :span="24">
                <el-form-item :label="$t('inventoryManagement.description')" prop="description" style="width:100%">
                    <el-input
                        type="textarea"
                        :autosize="{ minRows: 5, maxRows: 6}"
                        v-model="viewModel.description"
                        maxlength="1000"

                    >
                    </el-input>
                </el-form-item>
            </el-col> -->

                </el-row>

            </el-form>
        </el-card>
        <el-card class="box-card" style="margin-top:24px;">
            <div class="app-container">
                <div class="container-header">
                    <div class="hign-line"></div>
                    <div class="header-left">
                        {{$t('inventoryManagement.inspectionInfo')}}
                    </div>
                </div>
                <div class="container-table">
                    <el-table stripe v-loading="loading" ref="itemTable" :data="typeList" :height="400" border>
                        <!-- <el-table-column type="selection" width="55" align="center" /> -->
                        <el-table-column :label="$t('inventoryManagement.inspectionItems')" fixed="left" align="left" prop="projectName" minWidth="90" />
                        <el-table-column :label="$t('inventoryManagement.code')" fixed="left" align="left" prop="projectCode" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.inspectionType')" minWidth="110" fixed="left" align="left" prop="checkoutTypeCopy" />
                        <el-table-column :label="$t('inventoryManagement.targetValue')" fixed="left" align="left" prop="targetValue" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.lowerValue')" fixed="left" align="left" prop="lowerLimit" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.upperValue')" fixed="left" align="center" prop="upperLimit" />
                        <el-table-column :label="$t('inventoryManagement.inspectionTypeUnit')" minWidth="100" prop="unitName" align="left" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inspectionManagement.aroundFrequency')" minWidth="90" align="left" prop="itemFrequency" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.frequencyValue')" align="left" prop="itemFrequencyValue" :show-overflow-tooltip="true" />
                        <el-table-column label="样本量字码" align="left" prop="sampleCode" minWidth="120" :show-overflow-tooltip="true" />
                        <el-table-column label="接收数" align="left" prop="samAc" minWidth="120" :show-overflow-tooltip="true" />
                        <el-table-column label="拒收数" align="left" prop="samRe" minWidth="120" :show-overflow-tooltip="true" />
                        <!-- <el-table-column label="SN编号" align="left" prop="snNums" minWidth="120" :show-overflow-tooltip="true" /> -->
                        <el-table-column :label="$t('inventoryManagement.samplingScheme')" align="left" prop="samplingOne" minWidth="120" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.samplingOptions')" align="left" prop="samplingTwo" minWidth="80">
                            <template slot-scope="scope">
                                <span>{{scope.row.samplingTwo}}</span> <span>{{scope.row.samplingThree}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.samplingQuantity')" align="left" prop="samplingAmount" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.testMethod')" align="left" prop="detectionOne" :minWidth="200" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <span>{{scope.row.detectionOne}}</span> <span>{{scope.row.detectionTwo}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.specialCharacteristics')" align="left" prop="symbol" minWidth="110" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.decimalPlaces')" align="left" prop="decimalPlace" :show-overflow-tooltip="true" />
                        <!-- <el-table-column :label="$t('inventoryManagement.gapValue')" align="left" prop="gap" :show-overflow-tooltip="true" /> -->
                        <!-- <el-table-column :label="$t('inventoryManagement.inspectionValue')" align="center">
                            <el-table-column :label="item" v-for="(item,index) in tableHeader" :key="index" minWidth="160" align="center" prop="gap">
                                <template slot-scope="scope">
                                    <el-input-number @change="(e)=>valueChange(e,scope,index)" v-if="scope.row.checkoutType!=='布尔型'&&index<parseInt(scope.row.samplingAmount)" :controls="false" v-model="scope.row['value'+index]" clearable size="small" />
                                    <el-select v-if="scope.row.checkoutType==='布尔型'&&index===0" @change="(e)=>changeCheckoutValue(e,scope,index)" v-model="typeList[scope.$index]['value'+index]" style="width:100%;" clearable size="small">
                                        <el-option key="0" label="OK" value="OK" />
                                        <el-option key="1" label="NG" value="NG" />
                                    </el-select>
                                </template>
                            </el-table-column>
                        </el-table-column>

                        <el-table-column :label="$t('defectIncoming.smallDefect')" align="left" width="140" prop="inspectorName" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-autocomplete style="width:100%" size="small" popper-class="my-autocomplete" v-model="scope.row.flawProjectName" v-if="scope.row.checkoutResult===0" :fetch-suggestions="minFlawRemoteMethod" placeholder="请输入内容" @select="(e)=>handleMinFlawSelect(e,scope)">
                                    <i class="el-icon-search el-input__icon" slot="suffix">
                                    </i>
                                    <template slot-scope="{ item }">
                                        {{ item.minFlawName }}
                                    </template>
                                </el-autocomplete>
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.inspector')" align="left" prop="inspectorName" :show-overflow-tooltip="true" /> -->

                        <!-- <el-table-column :label="$t('public.upload')" prop="file" width="160" align="center" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <file-upload :ref="'projectItemFiles'+scope.$index" :isShowTip="false" :bizId="scope.row.id" @change="(fileList)=>fileChange(fileList,scope.$index)"></file-upload>
                            </template>
                        </el-table-column> -->
                        <el-table-column :label="$t('inspectionManagement.checkoutResult')" align="center" fixed="right" width="100">
                            <template slot-scope="scope">
                                <span v-if="scope.row.checkoutResult===0" class="result-tag-red">不合格</span>
                                <span v-else-if="scope.row.checkoutResult===1" class="result-tag-green">合格</span>
                                <span v-else class="labelN">未录入</span>
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('public.opera')" fixed="right" align="center" width="100">
                            <template slot-scope="scope">
                                <div class="action-wrap">
                                    <table-body-btn type="edit" :name="$t('public.edit')" @click.native="handleEdit(scope)" />
                                </div>
                            </template>
                        </el-table-column>

                        <!-- <el-table-column v-if="isEdit" :label="$t('public.opera')" fixed="right" align="center" width="100">
                            <template slot-scope="scope">
                                <div class="action-wrap">
                                    <table-body-btn type="edit" :name="$t('public.edit')" @click.native="handleEdit(scope)" />
                                </div>
                            </template>
                        </el-table-column> -->
                    </el-table>
                </div>
                <!-- <div class="container-table">
                    <el-table stripe v-loading="loading" :data="typeList" @selection-change="handleSelectionChange">
                        <el-table-column :label="$t('inventoryManagement.inspectionItems')" align="left" prop="inspectionItems" minWidth="160">
                            <template slot-scope="scope">
                                <el-select v-model="scope.row.projectName" filterable placeholder="请选择" @change="changeProject(scope)" size="mini">
                                    <el-option size="mini" v-for="item in projectList" :key="item.projectName" :label="item.projectName" :value="item.projectName">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.code')" align="left" prop="projectCode" minWidth="120" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-input v-model="scope.row.projectCode" size="small" />
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.inspectionTypeUnit')" minWidth="130" align="left" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-select v-model="scope.row.unitName" filterable placeholder="请选择" size="mini">
                                    <el-option size="mini" v-for="item in unitList" :key="item.unitName" :label="item.unitName" :value="item.unitName">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.frequency')" minWidth="110" align="left" prop="itemFrequency" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-select v-model="scope.row.itemFrequency" filterable placeholder="请选择" size="mini">
                                    <el-option size="mini" v-for="item in frequencyOptions" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.frequencyValue')" align="left" prop="itemFrequencyValue" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-input v-model="scope.row.itemFrequencyValue" clearable size="small" />
                            </template>
                        </el-table-column>

                        <el-table-column :label="$t('inventoryManagement.inspectionType')" minWidth="130" align="left" prop="checkoutType">
                            <template slot-scope="scope">
                                <el-select v-model="scope.row.checkoutType" filterable placeholder="请选择" size="mini">
                                    <el-option size="mini" v-for="item in inspectionTypeOptions" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-table-column>

                        <el-table-column :label="$t('inventoryManagement.decimalPlaces')" align="left" prop="decimalPlace" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-input v-model="scope.row.decimalPlace" v-show="scope.row.checkoutType!='布尔型'" clearable size="small" />
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.upperValue')" align="center" prop="upperLimit">
                            <template slot-scope="scope">
                                <el-input v-show="scope.row.checkoutType!='布尔型'" v-model="scope.row.upperLimit" clearable size="small" />
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.lowerValue')" align="left" prop="lowerLimit" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-input v-show="scope.row.checkoutType!='布尔型'" v-model="scope.row.lowerLimit" clearable size="small" />
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.targetValue')" align="left" prop="targetValue" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-input v-model="scope.row.targetValue" clearable size="small" />
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.samplingScheme')" align="left" prop="samplingOne" minWidth="140" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-select v-model="scope.row.samplingOne" filterable placeholder="请选择" size="mini">
                                    <el-option size="mini" v-for="item in samplingSchemeOptions" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.samplingQuantity')" align="left" prop="samplingAmount" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-input v-model="scope.row.samplingAmount" clearable size="small" />
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.testMethod')" align="left" prop="detectionOne" :minWidth="200" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-select v-model="scope.row.detectionOne" filterable placeholder="请选择" size="mini" :style="scope.row.detectionOne=='2'?'width:48%;margin-right:3px;float:left':'width:100%'">
                                    <el-option size="mini" v-for="item in testMethodOptions" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                                <measuring-tool-dialog v-show="scope.row.detectionOne=='2'" v-model="scope.row.detectionTwo" />
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.specialCharacteristics')" align="left" prop="symbol" minWidth="110" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-select v-model="scope.row.symbol" filterable placeholder="请选择" size="mini">
                                    <el-option size="mini" v-for="item in specialCharacteristicsOptions" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.gapValue')" minWidth="110" align="left" prop="gap" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-input v-model="scope.row.gap" clearable size="small" />
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.inspector')" minWidth="110" align="left" prop="inspectorName" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <select-user-dialog v-model="scope.row.inspector" />
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.inspectionValue')" align="center" :show-overflow-tooltip="true">
                            <el-table-column :label="item" v-for="(item,index) in tableHeader" :key="index" minWidth="110" align="center" prop="gap">
                                <template slot-scope="scope">
                                    <el-input v-if="scope.row.checkoutType!=='布尔型'" v-model="typeList[scope.$index]['value'+index]" @input="(e)=>valueChange(e,scope,index)" clearable size="small" />
                                    <el-select v-if="scope.row.checkoutType==='布尔型'" @change="(e)=>changeCheckoutValue(e,scope,index)" v-model="typeList[scope.$index]['value'+index]" style="width:100%;" clearable size="small">
                                        <el-option key="0" label="OK" value="OK" />
                                        <el-option key="1" label="NG" value="NG" />
                                    </el-select>
                                </template>
                            </el-table-column>
                        </el-table-column>
                        <el-table-column :label="$t('inspectionManagement.checkoutResult')" align="center" width="100">
                            <template slot-scope="scope">
                                <span v-if="scope.row.checkoutResult===0" class="result-tag-red">不合格</span>
                                <span v-else-if="scope.row.checkoutResult===1" class="result-tag-green">合格</span>
                            </template>
                        </el-table-column>
                    </el-table>
                </div> -->
            </div>
        </el-card>
        <el-card class="box-card" style="margin-top:24px">
            <div class="container-header">
                <div class="hign-line"></div>
                <div class="header-left">
                    {{$t('inspectionManagement.comprehensiveJudgment')}}
                </div>
            </div>
            <el-form :model="viewModel" ref="sumaryForm" v-show="showSearch" label-width="110px" :rules="sumaryRules">
                <el-row :gutter="24" class="mb8">
                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.destructiveMaterialInformation')" prop="destroyAmount">
                            <el-input v-model="viewModel.destroyAmount" clearable size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.judgmentResult')" prop="judgmentResult">
                            <span v-if="viewModel.decideResult===0||(viewModel.outerPacking==='1')||(viewModel.inspectionRohs==='1')||(viewModel.inspectionCoa==='1')" class="result-tag-red">不合格</span>
                            <span v-else-if="viewModel.decideResult===1" class="result-tag-green">合格</span>
                            <span v-else class="result-tag-yellow">暂无判定结果</span>
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.returnQuantity')" prop="returnAmount">
                            <el-input v-model="viewModel.returnAmount" clearable size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.concessionAcceptanceQuantity')" prop="concessionAccept">
                            <el-input v-model="viewModel.concessionAccept" clearable size="small" />
                        </el-form-item>
                    </el-col> -->

                    <el-col :span="24">
                        <el-form-item :label="$t('inventoryManagement.description')" prop="description" style="width:100%">
                            <el-input type="textarea" :autosize="{ minRows: 5, maxRows: 6}" v-model="viewModel.description" maxlength="1000">
                            </el-input>
                        </el-form-item>
                    </el-col>

                </el-row>

            </el-form>
        </el-card>
        <div class="submit-footer">
            <el-button icon="el-icon-close" size="small" @click="closeTab" class="drawer-close">{{$t('public.close')}}</el-button>
            <el-button type="primary" @click="submitForm" icon="el-icon-check" size="small">{{$t('public.submit')}}</el-button>
        </div>
        <el-drawer :with-header="false" :visible.sync="drawer" :title="$t('inspectionManagement.editInspectionItems')" size="50%" :direction="direction" :before-close="handleClose">
            <div class="app-container">
                <div class="container-header">
                    <div class="header-left">
                        {{$t('inspectionManagement.editInspectionItems')}}
                    </div>
                </div>
                <el-form :model="currentItem" ref="currentQueryForm" v-show="showSearch" :rules="queryFormRules" label-width="88px">
                    <el-row :gutter="24" class="mb8">
                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.inspectionItems')" prop="projectName">
                                <el-input v-model="currentItem.projectName" readonly clearable size="small" @keyup.enter.native="handleQuery" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.inspectionType')" prop="checkoutTypeCopy">
                                <el-input v-model="currentItem.checkoutTypeCopy" readonly clearable size="small" @keyup.enter.native="handleQuery" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.samplingQuantity')" prop="samplingAmount">
                                <el-input v-model="currentItem.samplingAmount" readonly clearable size="small" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" v-if="(currentItem.samplingOne==='GB/T2828.1-2012')&&currentItem.checkoutType==='布尔型'">
                            <el-form-item :label="$t('inspectionManagement.SampleSizeCode')" prop="sampleCode">
                                <el-input v-model="currentItem.sampleCode" readonly clearable size="small" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" v-if="!((currentItem.samplingOne==='GB/T2828.1-2012'||currentItem.samplingOne==='GB/T2828.2-2008')&&currentItem.checkoutType==='布尔型')">
                            <el-form-item :label="$t('inventoryManagement.lowerValue')" prop="lowerLimit">
                                <el-input v-model="currentItem.lowerLimit" readonly clearable size="small" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" v-if="!((currentItem.samplingOne==='GB/T2828.1-2012'||currentItem.samplingOne==='GB/T2828.2-2008')&&currentItem.checkoutType==='布尔型')">
                            <el-form-item :label="$t('inventoryManagement.upperValue')" prop="upperLimit">
                                <el-input v-model="currentItem.upperLimit" readonly clearable size="small" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" v-if="(currentItem.samplingOne==='GB/T2828.1-2012'||currentItem.samplingOne==='GB/T2828.2-2008')&&currentItem.checkoutType==='布尔型'">
                            <el-form-item :label="$t('inspectionManagement.ReceivedQuantity')" prop="samAc">
                                <el-input v-model="currentItem.samAc" readonly clearable size="small" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" v-if="(currentItem.samplingOne==='GB/T2828.1-2012')&&currentItem.checkoutType==='布尔型'">
                            <el-form-item :label="$t('inspectionManagement.RejectionNumber')" prop="samRe">
                                <el-input v-model="currentItem.samRe" readonly clearable size="small" />
                            </el-form-item>
                        </el-col>
                        <!--                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.gapValue')" prop="gap">
                                <el-input v-model="currentItem.gap" readonly clearable size="small" />
                            </el-form-item>
                        </el-col>-->

                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.inspector')" prop="inspectorName">
                                <el-input v-model="currentItem.inspectorName" readonly clearable size="small" />
                                <!-- <select-user-dialog v-model="currentItem.inspectorName" :placeholder="$t('public.select_holder',{select_holder: $t('inventoryManagement.inspector')})" :titleName="$t('defectIncoming.selectMan')" @callback="(id)=>userDataCallback(id)" /> -->
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" v-if="currentItem.checkoutType!=='布尔型'">
                            <el-form-item :label="$t('inventoryManagement.targetValue')" prop="targetValue">
                                <el-input v-model="currentItem.targetValue" readonly size="small" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="24" v-if="currentItem.checkoutType==='布尔型'">
                            <el-form-item :label="$t('inventoryManagement.targetValue')" prop="targetValue">
                                <el-input v-model="currentItem.targetValue" resize="none" readonly type="textarea" :rows="3" size="small" />
                            </el-form-item>
                        </el-col>
                        <template v-if="currentItem.checkoutType==='数值'">
                        <el-col :span="8" >
                            <el-form-item :label="$t('outlier.min')" prop="minimum">
                                <el-input v-model="currentItem.minimum" readonly clearable size="small" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" >
                            <el-form-item :label="$t('outlier.max')" prop="maximum">
                                <el-input v-model="currentItem.maximum" readonly clearable size="small" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" >
                            <el-form-item :label="$t('outlier.averageValue')" prop="meanValue">
                                <el-input v-model="currentItem.meanValue" readonly clearable size="small" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" >
                            <el-form-item :label="$t('outlier.range')" prop="rangeValue">
                                <el-input v-model="currentItem.rangeValue" readonly clearable size="small" />
                            </el-form-item>
                        </el-col>
                        </template>
                        <el-col :span="24">
                            <el-form-item label=" ">
                                <el-table border stripe v-loading="loading" :data="currentItem.inspectionValues" max-height="300" style="margin-top:5px">
                                    <el-table-column type="index" width="55" align="center"></el-table-column>
                                    <el-table-column :label="$t('inspectionManagement.QualifiedQuantity')" align="left" prop="inspectionValue" v-if="(currentItem.samplingOne==='GB/T2828.1-2012'||currentItem.samplingOne==='GB/T2828.2-2008')&&currentItem.checkoutType==='布尔型'">
                                        <template slot-scope="scope">
                                            <div>
                                                <el-input v-model="scope.row.inspectionValue" :class="'input'+scope.$index" type="number" @input="(e)=>acceptChange(e,scope)" clearable size="small" />
                                            </div>

                                        </template>
                                    </el-table-column>
                                    <el-table-column :label="$t('inventoryManagement.inspectionValue')" align="left" prop="inspectionValue" v-else>
                                        <template slot-scope="scope">
                                            <div>
                                                <el-select transfer :popper-append-to-body="false" v-if="currentItem.checkoutType==='布尔型'" @change="(e)=>changeCheckoutValue(e,scope)" v-model="scope.row.inspectionValue" style="width:100%;" clearable size="small">
                                                    <el-option key="0" label="OK" value="OK" />
                                                    <el-option key="1" label="NG" value="NG" />
                                                    <el-option key="2" label="NA" value="NA" />
                                                </el-select>
                                                <el-input v-else v-model="scope.row.inspectionValue" :class="'input'+scope.$index" type="number" @input="(e)=>valueChange(e,scope)" @keyup.enter.native="nextInput('input'+(scope.$index+1),scope.$index)" clearable size="small" />
                                            </div>

                                        </template>
                                    </el-table-column>

                                    <el-table-column :label="((currentItem.samplingOne==='GB/T2828.1-2012'||currentItem.samplingOne==='GB/T2828.2-2008')&&currentItem.checkoutType==='布尔型')?'不合格数':$t('inventoryManagement.resultValue')" align="left" prop="resultValue" :show-overflow-tooltip="true" />
                                    <el-table-column :label="$t('inspectionManagement.judgmentResult')" align="left" :show-overflow-tooltip="true">
                                        <template slot-scope="scope">
                                            <div v-show="scope.row.resultValue">
                                                <span v-if="scope.row.resultType===0" class="result-tag-red">不合格</span>
                                                <span v-if="scope.row.resultType===1" class="result-tag-green">合格</span>
                                                <span v-if="scope.row.resultType===2" class="result-tag-yellow">NA</span>
                                            </div>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item :label="$t('defectIncoming.inspectResults')" v-show="comprehensiveResults!==''">
                                <span :class="comprehensiveResults==='不合格'?'result-tag-red':'result-tag-green'">{{comprehensiveResults}}</span>
                            </el-form-item>
                        </el-col>

                        <el-col :span="24" v-if="comprehensiveResults==='不合格'">
                            <el-form-item label=" ">
                                <el-button type="primary" @click="addFlaw" icon="el-icon-check" size="mini">新增小缺陷</el-button>
                            </el-form-item>

                            <el-form-item label="小缺陷">
                                <el-table border stripe v-loading="loading" :data="currentItem.flawList" max-height="300">
                                    <el-table-column type="index" width="55" align="center"></el-table-column>

                                    <el-table-column label="缺陷名称" align="left" prop="minFlawName">
                                        <template slot-scope="scope">
                                            <div>
                                                <el-select transfer :popper-append-to-body="false" filterable v-model="scope.row.minFlawName" style="width:100%;" clearable size="small">
                                                    <el-option v-for="item in minFlawOptions" @click.native="changeFlaw(item,scope)" :key="item.id" :label="item.minFlawName" :value="item.minFlawName" />
                                                </el-select>
                                            </div>

                                        </template>
                                    </el-table-column>
                                    <el-table-column label="缺陷数量" align="left" prop="minFlawNr">
                                        <template slot-scope="scope">
                                            <div>
                                                <el-input v-model="scope.row.minFlawNr" type="number" clearable size="small" />
                                            </div>

                                        </template>
                                    </el-table-column>
                                    <el-table-column label="操作" align="left" prop="minFlawNr" width="80">
                                        <template slot-scope="scope">
                                            <table-body-btn type="gwdelete" @click.native="deleteFlaw(scope)" />

                                        </template>
                                    </el-table-column>
                                </el-table>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item :label="$t('public.upload')">
                                <file-upload ref="projectItemFiles" :bizId="rowId" @change="(fileList)=>fileChange(fileList)"></file-upload>
                            </el-form-item>
                        </el-col>
                    </el-row>

                </el-form>
            </div>
            <div class="drawer-footer">
                <el-button icon="el-icon-close" size="mini" @click="drawerClose" class="drawer-close">{{$t('public.cancel')}}</el-button>
                <!-- <el-button icon="el-icon-refresh" class="resectBtn drawer-close"  size="mini"  >{{$t('public.reset')}}</el-button> -->
                <el-button type="primary" @click="drawerSubmit" icon="el-icon-check" size="mini">{{'保存'}}</el-button>
            </div>
        </el-drawer>
        <template-dialog :visible.sync="templateVisible" />
    </div>

</template>

<script>
import {getType, refreshCache,} from '@/api/basic/dict/type'
import {getNoticeList} from '@/api/system/message'
import {mapGetters} from 'vuex'
import FileUploadInput from '@/components/FileUploadInput'
import SupplierDialog from '@/views/components/SupplierDialog'
import MaterialDialog from '@/views/components/MaterialDialog'
import TemplateDialog from '@/views/components/TemplateDialog'
import MeasuringToolDialog from '@/views/components/MeasuringToolDialog'
import {getCollection, getIncomingDetail, getMinFlawAll,} from '@/api/inspectionManagement/inspectionManagement'
import {listProject} from '@/api/basic/project'
import {listCheckoutUnit} from '@/api/basic/checkoutUnit'
import SelectUserDialog from '@/views/components/SelectUserDialog'
import {geFileByBiz} from '@/api/file/file'

export default {
    name: 'inspectionExemption',
    dicts: ['sys_normal_disable'],
    components: {
        FileUploadInput,
        SupplierDialog,
        MaterialDialog,
        TemplateDialog,
        MeasuringToolDialog,
        SelectUserDialog,
    },
    data() {
        return {
            currentItem: {
                projectName: '',
                checkoutType: '',
                lowerLimit: '',
                upperLimit: '',
                samplingAmount: '',
                gap: '',
                flawProjectName: '',
                inspectorName: '',
                row: {},
            },
            queryFormRules: {
                flawProjectName: [
                    {
                        required: true,
                        message: '小缺陷不能为空',
                        trigger: 'blur',
                    },
                ],
                inspectorName: [
                    {
                        required: true,
                        message: '检验员不能为空',
                        trigger: 'blur',
                    },
                ],
            },
            comprehensiveResults: '',
            direction: 'rtl',
            addInspectionExemption: false,
            templateVisible: false,
            drawer: false,
            approvalOpen: false,
            viewInspectionExemption: false,
            projectList: [],
            unitList: [],

            inspectionOptions: [
                {
                    value: '1',
                    label: '检验项1',
                },
                {
                    value: '2',
                    label: '检验项2',
                },
            ],
            inspectionTypeUnitOptions: [
                {
                    value: '1',
                    label: '单位1',
                },
                {
                    value: '2',
                    label: '单位2',
                },
            ],
            inspectionTypeOptions: [
                {
                    value: '1',
                    label: '数值',
                },
                {
                    value: '2',
                    label: '布尔型',
                },
            ],
            frequencyOptions: [
                {
                    value: '1',
                    label: '批',
                },
                {
                    value: '2',
                    label: '件',
                },
                {
                    value: '3',
                    label: '年',
                },
                {
                    value: '4',
                    label: '季',
                },
                {
                    value: '5',
                    label: '月',
                },
            ],
            samplingSchemeOptions: [
                {
                    value: '1',
                    label: 'GB/T2828.1-2012',
                },
                {
                    value: '2',
                    label: '百分比',
                },
                {
                    value: '3',
                    label: '固定抽样',
                },
                {
                    value: '4',
                    label: 'C=0',
                },
            ],
            testMethodOptions: [
                {
                    value: '1',
                    label: '目测',
                },
                {
                    value: '2',
                    label: '量具',
                },
                {
                    value: '3',
                    label: '验证',
                },
            ],
            samplingLevelOptions: [
                {
                    value: '1',
                    label: 'S-1',
                },
                {
                    value: '2',
                    label: 'S-2',
                },
                {
                    value: '3',
                    label: 'S-3',
                },
                {
                    value: '4',
                    label: 'S-4',
                },
            ],
            samplingLevelTypeOptions: [
                {
                    value: '1',
                    label: '正常',
                },
                {
                    value: '2',
                    label: '放宽',
                },
                {
                    value: '3',
                    label: '加严',
                },
            ],
            samplingFixedTypeOptions: [
                {
                    value: '1',
                    label: '批',
                },
                {
                    value: '2',
                    label: '件',
                },
            ],
            specialCharacteristicsOptions: [
                {
                    value: '1',
                    label: 'CC',
                },
                {
                    value: '2',
                    label: 'SC',
                },
            ],
            addModel: {},
            viewModel: {
                destroyAmount: '',
                returnAmount: '',
                concessionAccept: '',
                description: '',
                file: null,
                inspectionExemptionPlan: '1',
                inspectionCoa: 0,
                inspectionRohs: 0,
                outerPacking: 0,
                destroyAmount: 0,
            },
            editModel: {},
            approvalForm: {
                status: '1',
                textarea: '',
            },
            selBtn: 1,
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 字典表格数据
            typeList: [],
            tableHeader: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            id: this.$route.params.id,
            // 日期范围
            dateRange: [],
            samplingAmount: 0,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 20,
                noticeTitle: undefined,
                noticeType: undefined,
                hasRead: undefined,
                createTime: undefined,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                materialName: [
                    {
                        required: true,
                        message: this.$t('formValidation.materialNameCannotBeEmpty'),
                        trigger: 'blur',
                    },
                ],
                materialNo: [
                    {
                        required: true,
                        message: '物料编号不能为空',
                        trigger: 'blur',
                    },
                ],
                supplierNo: [
                    {
                        required: true,
                        message: '供应商编号不能为空',
                        trigger: 'blur',
                    },
                ],
            },
            sumaryRules: {},
            fullscreen: false,
        }
    },
    created() {
        this.getList()
        this.getAdditionInfo()
        this.getProjectList()
        this.getUnitList()
    },
    computed: {
        ...mapGetters(['userId', 'name']),
    },
    methods: {
        acceptChange(e, scope) {
            if (e === '' || e === null || e === undefined) {
                this.currentItem.inspectionValues[scope.$index].resultType = ''
                this.currentItem.inspectionValues[scope.$index].resultValue = ''
            } else {
                let resultValue = undefined
                if (
                    parseFloat(e) > parseFloat(this.currentItem.samplingAmount)
                ) {
                    this.$modal.msgError('合格数量不能超过抽样数量!')
                    this.currentItem.inspectionValues[
                        scope.$index
                    ].inspectionValue = this.currentItem.samplingAmount
                    resultValue = 0
                } else {
                    resultValue =
                        parseFloat(this.currentItem.samplingAmount) -
                        parseFloat(e)
                }

                console.log(resultValue)
                if (this.currentItem.samplingOne === 'GB/T2828.1-2012') {
                    let resultType = 1
                    resultValue = resultValue.toFixed(0)
                    if (
                        parseInt(resultValue) >
                            parseInt(this.currentItem.samRe) ||
                        parseInt(resultValue) ===
                            parseInt(this.currentItem.samRe)
                    ) {
                        resultType = 0
                    }
                    this.currentItem.inspectionValues[
                        scope.$index
                    ].resultValue = resultValue
                    this.currentItem.inspectionValues[scope.$index].resultType =
                        resultType
                }
                if (this.currentItem.samplingOne === 'GB/T2828.2-2008') {
                    let resultType = 1
                    resultValue = resultValue.toFixed(0)
                    if (
                        parseInt(resultValue) > parseInt(this.currentItem.samAc)
                    ) {
                        resultType = 0
                    }
                    this.currentItem.inspectionValues[
                        scope.$index
                    ].resultValue = resultValue
                    this.currentItem.inspectionValues[scope.$index].resultType =
                        resultType
                }
            }

            this.judgeQualifid()
            this.$forceUpdate()
        },
        deleteFlaw(scope) {
            this.currentItem.flawList.splice(scope.$index, 1)
        },
        changeFlaw(item, scope) {
            this.currentItem.flawList[scope.$index].minFlawName =
                item.minFlawName
            this.currentItem.flawList[scope.$index].minFlawCode =
                item.minFlawCode
            this.currentItem.flawList[scope.$index].minFlawId = item.id
        },
        addFlaw() {
            this.currentItem.flawList.push({
                minFlawNr: null,
                minFlawName: null,
                minFlawId: null,
                minFlawCode: null,
                classId: this.currentItem.id,
            })
        },
        drawerSubmit() {
            this.$refs['currentQueryForm'].validate((valid) => {
                if (valid) {
                    this.drawer = false
                    let itemResult = 1
                    let checkoutValue = ''
                    let resultValue = ''
                    let values = []
                    let resultValues = []
                    console.log(this.currentItem.inspectionValues)
                    this.currentItem.inspectionValues.forEach((io) => {
                        values.push(io.inspectionValue)
                        resultValues.push(io.resultValue)
                        if (io.resultType === 0) {
                            itemResult = 0
                        }
                    })
                    checkoutValue = values.join(',')
                    resultValue = resultValues.join(',')
                    this.typeList[this.currentItem.index].checkoutValue =
                        checkoutValue
                    this.typeList[this.currentItem.index].result = itemResult
                    this.typeList[this.currentItem.index].flawProjectName = this
                        .currentItem.flawProjectName
                        ? this.currentItem.flawProjectName.join(';')
                        : this.currentItem.flawProjectName
                    this.typeList[this.currentItem.index].inspectorName =
                        this.currentItem.inspectorName
                    this.typeList[this.currentItem.index].inspector =
                        this.currentItem.inspector
                    this.typeList[this.currentItem.index].resultValue =
                        resultValue
                    this.typeList[this.currentItem.index].flawList =
                        this.currentItem.flawList
                    // this.typeListKey++
                    if (this.comprehensiveResults === '合格') {
                        this.typeList[this.currentItem.index].checkoutResult = 1
                    }
                    if (this.comprehensiveResults === '不合格') {
                        this.typeList[this.currentItem.index].checkoutResult = 0
                    }
                    if (this.comprehensiveResults === '') {
                        this.typeList[this.currentItem.index].checkoutResult =
                            ''
                    }

                    this.comprehensiveResults = ''

                    this.buildInspectionResult()
                    this.$forceUpdate()
                    console.log(
                        'this.currentItem.index]================',
                        this.typeList[this.currentItem.index].checkoutValue
                    )
                }
            })
        },
        valueChange(e, scope) {
            if (e === '' || e === null || e === undefined) {
                this.currentItem.inspectionValues[scope.$index].resultType = ''
                this.currentItem.inspectionValues[scope.$index].resultValue = ''
            } else {
                console.log(scope.$index)
                let resultValue =
                    parseFloat(e) +
                    (this.currentItem.gap.length > 0
                        ? parseFloat(this.currentItem.gap)
                        : 0)
                let resultType = 1
                if (
                    this.currentItem.decimalPlace != '' &&
                    this.currentItem.decimalPlace != null &&
                    this.currentItem.decimalPlace != undefined
                ) {
                    resultValue = resultValue.toFixed(
                        parseInt(this.currentItem.decimalPlace)
                    )
                } else {
                    resultValue = resultValue.toFixed(2)
                }

                if (
                    resultValue > parseFloat(this.currentItem.upperLimit) ||
                    resultValue < parseFloat(this.currentItem.lowerLimit)
                ) {
                    resultType = 0
                }
                console.log(resultValue)
                this.currentItem.inspectionValues[scope.$index].resultValue =
                    resultValue
                this.currentItem.inspectionValues[scope.$index].resultType =
                    resultType
            }

            console.log(this.currentItem.inspectionValues)
            this.judgeQualifid()
            this.$forceUpdate()
        },
        handleMinFlawSelect(e, scope) {
            // this.dialogForm.materialType = e
            this.typeList[scope.$index].flawProjectName = e.minFlawName
            this.$forceUpdate()
        },
        getMinFlawAll(val, cb) {
            //getMinFlawAll({ materialType: val }).then((res) => {
            //    this.minFlawOptions = res.data
            //})
            getMinFlawAll().then((res) => {
                this.minFlawOptions = res.data
            })
        },
        nextInput(className, index) {
            if (
                parseInt(index) + 1 ===
                this.currentItem.inspectionValues.length
            ) {
                return
            }
            let ele = document.querySelector(
                '.' + className + ' .el-input__inner'
            )
            // let inputDoms = ele.querySelectorAll('.el-input__inner')
            console.log(ele)
            ele.focus()
            // console.log(document.getElementsByClassName(className))
        },
        // 判断检验结果是否合格
        judgeQualifid() {
            const resultValues = this.currentItem.inspectionValues.map(
                (item) => item.resultValue
            )
            const resultTypes = this.currentItem.inspectionValues.map(
                (item) => item.resultType
            )
            console.log(resultTypes)
            console.log(resultValues)
            if (resultValues.length) {
                if (resultValues.includes('') || resultValues.includes(null)) {
                    this.comprehensiveResults = ''
                } else {
                    if (resultTypes.includes(0)) {
                        this.comprehensiveResults = '不合格'
                    } else {
                        this.comprehensiveResults = '合格'
                    }
                }
            }
        },
        changeCheckoutValue(e, scope, index) {
            if (e === 'OK') {
                this.typeList[scope.$index].checkoutResult = 1
            } else {
                this.typeList[scope.$index].checkoutResult = 0
            }
            this.typeList[scope.$index]['value' + index] = e
            this.typeList[scope.$index].resultValue = e
            this.judgeQualifid()
            this.$forceUpdate()
        },
        changeCheckoutValue(e, scope) {
            this.currentItem.inspectionValues[scope.$index].resultValue = e
            if (e === 'OK') {
                this.currentItem.inspectionValues[scope.$index].resultType = 1
            } else {
                this.currentItem.inspectionValues[scope.$index].resultType = 0
            }
            this.judgeQualifid()
        },
        getCheckoutResult(
            data,
            upperLimit,
            lowerLimit,
            gap,
            checkoutType,
            decimalPlace,
            samplingOne,
            samplingAmount,
            samRe,
            samAc
        ) {
            let checkoutValue = data ? data.split(',') : []
            let inspectionValues = []

            console.log(checkoutValue, 'checkoutValue=====')

            for (let i = 0; i < checkoutValue.length; i++) {
                let inspectionValue = checkoutValue[i]
                    ? parseFloat(checkoutValue[i])
                    : null
                let resultValue = null
                let resultType = null
                if (checkoutType === '布尔型') {
                    resultValue = inspectionValue
                    resultType =
                        resultValue === 'OK' ? 1 : resultValue === 'NA' ? 2 : 0
                } else {
                    resultValue = checkoutValue[i]
                        ? parseFloat(checkoutValue[i]) +
                          (gap && gap.length > 0 ? parseFloat(gap) : 0)
                        : null
                    if (
                        decimalPlace != '' &&
                        decimalPlace != null &&
                        decimalPlace != undefined
                    ) {
                        resultValue = resultValue
                            ? resultValue.toFixed(parseInt(decimalPlace))
                            : resultValue
                    } else {
                        resultValue = resultValue
                            ? resultValue.toFixed(2)
                            : resultValue
                    }

                    if (
                        resultValue > parseFloat(upperLimit) ||
                        resultValue < parseFloat(lowerLimit)
                    ) {
                        resultType = 0
                    }
                    if (
                        (resultValue < parseFloat(upperLimit) ||
                            resultValue == parseFloat(upperLimit)) &&
                        (resultValue > parseFloat(lowerLimit) ||
                            resultValue == parseFloat(lowerLimit))
                    ) {
                        resultType = 1
                    }
                }
                inspectionValues.push({
                    inspectionValue,
                    resultValue,
                    resultType,
                })
            }
            console.log(inspectionValues, 'inspectionValues=====')
            const resultTypes = inspectionValues.map((item) => item.resultType)
            if (checkoutValue.includes('')) {
                return ''
            }
            if (checkoutType === '布尔型' && checkoutValue.length > 0) {
                if (samplingOne === 'GB/T2828.1-2012') {
                    let tempValue =
                        parseInt(samplingAmount) - parseInt(checkoutValue[0])
                    return parseInt(tempValue) > parseInt(samRe) ||
                        parseInt(tempValue) === parseInt(samRe)
                        ? 0
                        : 1
                } else if (samplingOne === 'GB/T2828.2-2008') {
                    let tempValue =
                        parseInt(samplingAmount) - parseInt(checkoutValue[0])
                    return parseInt(tempValue) > parseInt(samAc) ? 0 : 1
                } else {
                    return checkoutValue == 'OK'
                        ? 1
                        : checkoutValue == 'NA'
                        ? 2
                        : 0
                }
            }
            if (resultTypes.length) {
                if (resultTypes.includes(0)) {
                    return 0
                } else {
                    return 1
                }
            }
        },
        formatTargetValueTo(targetValue) {
            if (
                Object.prototype.toString.call(targetValue) !==
                '[object String]'
            ) {
                return ''
            }
            return targetValue.replace(/&lt;|&gt;|&amp;/g, function (match) {
                return {
                    '&lt;': '<',
                    '&gt;': '>',
                    '&amp;': '&',
                }[match]
            })
        },
        formatTargetValueForward(targetValue) {
            if (
                Object.prototype.toString.call(targetValue) !==
                '[object String]'
            ) {
                return ''
            }
            return targetValue.replace(/<|>|&/g, function (match) {
                return {
                    '<': '&lt;',
                    '>': '&gt;',
                    '&': '&amp;',
                }[match]
            })
        },
        getAdditionInfo() {
            getIncomingDetail(this.id).then((response) => {
                this.viewModel = response.data

                let typeList = response.data.classList
                typeList.forEach((io) => {
                    io.inspectorName = this.name
                    io.inspector = this.userId
                    io.targetValue = this.formatTargetValueTo(io.targetValue)
                    io.comprehensiveResults = ''
                    if (io.inspector) {
                        io.checkoutResult = this.getCheckoutResult(
                            io.checkoutValue,
                            io.upperLimit,
                            io.lowerLimit,
                            io.gap,
                            io.checkoutType,
                            io.decimalPlace,
                            io.samplingOne,
                            io.samplingAmount,
                            io.samRe,
                            io.samAc
                        )
                    }
                    console.log(this.name)
                    // if(){

                    // }
                })
                this.typeList = typeList
                this.getMinFlawAll(this.viewModel.materialType)
                // this.getFlowByMaterialCode(this.viewModel.materialCode)
                this.buildInspectionResult()
                this.loading = false
            })
        },
        buildInspectionResult() {
            let failResultCount = 0
            let passResultCount = 0
            let unsetResultCount = 0
            this.typeList.forEach((io) => {
                if (io.checkoutResult === 0) {
                    failResultCount++
                }
                if (io.checkoutResult === 1) {
                    passResultCount++
                }
                if (io.checkoutResult === '') {
                    unsetResultCount++
                }
                console.log(passResultCount)
            })
            console.log(this.typeList, 'failResultCount')

            if (unsetResultCount > 0) {
                this.viewModel.decideResult = ''
                return
            }
            if (
                passResultCount + failResultCount == this.typeList.length &&
                this.typeList.length > 0
            ) {
                if (failResultCount > 0) {
                    this.viewModel.decideResult = 0
                } else {
                    this.viewModel.decideResult = 1
                }
            }
            console.log(passResultCount)
        },

        getUnitList() {
            listCheckoutUnit().then((res) => {
                this.unitList = res.rows
            })
        },
        changeProject(e) {
            let obj = this.projectList.find((item) => {
                return item.projectName === e.row.projectName
            })
            this.typeList[e.$index].projectCode = obj.projectCode
            this.typeList[e.$index].projectId = obj.projectId
        },
        getProjectList() {
            listProject().then((res) => {
                this.projectList = res.rows
            })
        },
        supplierDataCallback(row) {
            this.viewModel.supplierNo = row.supplierNo
            this.viewModel.supplierType = row.supplierType
        },
        materialDataCallback(row) {
            this.viewModel.materialNo = row.materialNo
            this.viewModel.materialType = row.materialType
            this.viewModel.maturity = row.maturity
            this.viewModel.materialTypeName = row.materialTypeName
        },
        closeTab() {
            this.$router.push({ path: '/inspect/incoming' })
        },
        effectDateChange(e, scope) {
            if (parseInt(e) > 0) {
                this.typeList[scope.$index].endDate = this.getNewDay(
                    scope.row.approvalTime,
                    e
                )
            }
        },
        getNewDay(dateTemp, days) {
            var dateTemp = dateTemp.split('-')
            //转换为MM-DD-YYYY格式
            var nDate = new Date(
                dateTemp[1] + '-' + dateTemp[2] + '-' + dateTemp[0]
            )
            var millSeconds = Math.abs(nDate) + days * 24 * 60 * 60 * 1000
            var rDate = new Date(millSeconds)
            var year = rDate.getFullYear()
            var month = rDate.getMonth() + 1
            if (month < 10) month = '0' + month
            var date = rDate.getDate()
            if (date < 10) date = '0' + date
            return year + '-' + month + '-' + date
        },
        fileChange(e) {
            console.log(e)
        },
        drawerClose() {
            this.drawer = false
        },
        /** 查询字典类型列表 */
        getList() {
            this.loading = true
            this.typeList = [
                {
                    approvalTime: '2022-05-19',
                    endDate: '',
                    measuringTool: null,
                },
            ]
            getNoticeList(this.queryParams).then((response) => {
                if (response.code == 200 && response.rows) {
                    //   this.typeList = response.rows;
                    this.total = response.total
                    this.loading = false
                }
            })
        },
        // 取消按钮
        cancel() {
            this.open = false
            this.reset()
        },
        // 表单重置
        reset() {
            this.form = {
                dictId: undefined,
                dictName: undefined,
                dictType: undefined,
                status: '0',
                remark: undefined,
            }
            this.resetForm('form')
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = []
            this.resetForm('queryForm')
            this.handleQuery()
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.typeList.push({})
        },
        handleSelectTemplate() {
            this.templateVisible = true
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map((item) => item.dictId)
            this.single = selection.length != 1
            this.multiple = !selection.length
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset()
            const dictId = row.dictId || this.ids
            getType(dictId).then((response) => {
                this.form = response.data
                this.open = true
                this.title = '修改字典类型'
            })
        },
        /** 提交按钮 */
        submitForm: function () {
            this.$refs['sumaryForm'].validate((valid) => {
                if (valid) {
                    let typeList = [...this.typeList]
                    typeList.forEach((io) => {
                        io.targetValue = this.formatTargetValueForward(
                            io.targetValue
                        )
                    })
                    let submitData = { ...this.viewModel, classList: typeList }
                    console.log(JSON.stringify(submitData))
                    getCollection(submitData).then((response) => {
                        this.$modal.msgSuccess('提交成功!')
                        this.$router.push({ path: '/inspect/incoming' })
                    })
                } else {
                    console.log('error submit!!')
                    return false
                }
            })
        },
        /** 发起检验提交 */
        submitAddForm: function () {
            this.$modal.msgSuccess('发起成功!')
            this.addInspection = false
        },

        /** 删除按钮操作 */
        handleDelete(row) {
            if (this.typeList.length === 1) {
                this.$modal.msgWarning('请至少保留一条检验项!')
                return
            }
            this.typeList.splice(row.$index, 1)
        },
        /** 查看按钮操作 */
        handleView(row) {
            this.form = row
            this.viewInspectionExemption = true
            //   if(row.hasRead == 0){
            //     readNotice(row.noticeId).then(res=>{
            //       if(res.code == 200){
            //         this.handleQuery()
            //       }
            //     })
            //   }
        },
        /** 编辑按钮操作 */
        /** 编辑按钮操作 */
        handleEdit(scope) {
            let currentItem = JSON.parse(JSON.stringify(scope.row))
            currentItem.flawList = currentItem.flawList
                ? currentItem.flawList
                : []
            this.comprehensiveResults = ''
            if (
                currentItem.inspectorName === null ||
                currentItem.inspectorName === undefined ||
                currentItem.inspectorName === ''
            ) {
                currentItem.inspectorName = this.name
                currentItem.inspector = this.userId
            } else {
                this.currentItem.inspectorName = currentItem.inspectorName
                this.currentItem.inspector = currentItem.inspector
            }

            console.log(currentItem, 'currentItem')
            currentItem.index = scope.$index
            let checkoutValue = currentItem.checkoutValue
                ? currentItem.checkoutValue.split(',')
                : []
            let inspectionValues = []
            for (let i = 0; i < currentItem.samplingAmount; i++) {
                let inspectionValue = checkoutValue[i] ? checkoutValue[i] : ''

                let resultValue = null
                let resultType = null
                if (scope.row.checkoutType === '布尔型') {
                    if (scope.row.samplingOne === 'GB/T2828.1-2012') {
                        resultValue =
                            parseInt(scope.row.samplingAmount) -
                            parseInt(inspectionValue)
                        if (
                            inspectionValue === '' ||
                            inspectionValue === null ||
                            inspectionValue === undefined
                        ) {
                            resultValue = null
                            resultType = null
                        } else if (
                            resultValue > parseInt(scope.row.samRe) ||
                            resultValue === parseInt(scope.row.samRe)
                        ) {
                            resultType = 0
                        } else {
                            resultType = 1
                        }
                    } else if (scope.row.samplingOne === 'GB/T2828.2-2008') {
                        resultValue =
                            parseInt(scope.row.samplingAmount) -
                            parseInt(inspectionValue)
                        if (
                            inspectionValue === '' ||
                            inspectionValue === null ||
                            inspectionValue === undefined
                        ) {
                            resultValue = null
                            resultType = null
                        } else if (resultValue > parseInt(scope.row.samAc)) {
                            resultType = 0
                        } else {
                            resultType = 1
                        }
                    } else {
                        resultValue = inspectionValue
                        if (resultValue === 'OK') {
                            resultType = 1
                        } else if (resultValue === 'NA') {
                            resultType = 2
                        } else if (resultValue === 'NG') {
                            resultType = 0
                        } else {
                            resultType = null
                        }
                    }
                } else {
                    resultValue = checkoutValue[i]
                        ? parseFloat(
                              checkoutValue[i] && checkoutValue[i].length > 0
                                  ? parseFloat(checkoutValue[i])
                                  : checkoutValue[i] + currentItem.gap &&
                                    currentItem.gap.length > 0
                                  ? parseFloat(currentItem.gap)
                                  : currentItem.gap
                          )
                        : null
                    if (
                        currentItem.decimalPlace != '' &&
                        currentItem.decimalPlace != null &&
                        currentItem.decimalPlace != undefined
                    ) {
                        resultValue = resultValue
                            ? resultValue.toFixed(
                                  parseInt(currentItem.decimalPlace)
                              )
                            : resultValue
                    } else {
                        resultValue = resultValue
                            ? resultValue.toFixed(2)
                            : resultValue
                    }
                    if (
                        resultValue > parseFloat(currentItem.upperLimit) ||
                        resultValue < parseFloat(currentItem.lowerLimit)
                    ) {
                        resultType = 0
                        if (checkoutValue.length > 0) {
                            this.comprehensiveResults = '不合格'
                        }
                    }
                    if (
                        (resultValue < parseFloat(currentItem.upperLimit) ||
                            resultValue ==
                                parseFloat(currentItem.upperLimit)) &&
                        (resultValue > parseFloat(currentItem.lowerLimit) ||
                            resultValue == parseFloat(currentItem.lowerLimit))
                    ) {
                        resultType = 1
                        if (checkoutValue.length > 0) {
                            this.comprehensiveResults = '合格'
                        }
                    }
                }

                if (scope.row.checkoutType === '布尔型' && i > 0) {
                    continue
                }
                inspectionValues.push({
                    inspectionValue,
                    resultValue,
                    resultType,
                })
            }
            console.log(inspectionValues)
            if (checkoutValue.includes('') || checkoutValue.includes(null)) {
                this.comprehensiveResults = ''
            }
            if (currentItem.checkoutResult === 1) {
                this.comprehensiveResults = '合格'
            }
            if (currentItem.checkoutResult === 2) {
                this.comprehensiveResults = 'NA'
            }
            if (currentItem.checkoutResult === 0) {
                this.comprehensiveResults = '不合格'
            }
            if (currentItem.checkoutResult === '') {
                this.comprehensiveResults = ''
            }
            currentItem.flawProjectName = scope.row.flawProjectName
                ? scope.row.flawProjectName.split(';')
                : scope.row.flawProjectName
            currentItem.inspectionValues = inspectionValues
            console.log(currentItem.inspectionValues)
            this.currentItem = currentItem
            this.rowId = scope.row.id
            this.getItemFileById(this.rowId)
            this.drawer = true
            // this.judgeQualifid()
        },
        getItemFileById(id) {
            geFileByBiz({ bizId: id }).then((res) => {
                let itemFileList = []
                res.data.forEach((io) => {
                    if (io.bizType === 'UPLOAD_FILE_ITEM') {
                        itemFileList.push(io)
                    }
                })
                this.itemFileList = itemFileList
            })
        },
        geFileByBiz(id) {
            geFileByBiz({ bizId: id }).then((res) => {
                let otherList = []
                res.data.forEach((io) => {
                    if (io.bizType === 'UPLOAD_FILE_OTHERS') {
                        otherList.push(io)
                    }
                })
                this.otherList = otherList
                console.log('otherList=========', this.otherList)
            })
        },
        /** 关闭抽屉操作 */
        handleClose(row) {
            this.drawer = false
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download(
                'system/dict/type/export',
                {
                    ...this.queryParams,
                },
                `type_${new Date().getTime()}.xlsx`
            )
        },
        /** 刷新缓存按钮操作 */
        handleRefreshCache() {
            refreshCache().then(() => {
                this.$modal.msgSuccess('刷新成功')
            })
        },
    },
}
</script>
<style lang="scss" scoped>
::v-deep .el-card {
    padding-top: 20px;
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    padding-bottom: 20px;
}
::v-deep .el-aside {
    padding: 0;
    margin-bottom: 0;
}
.content-style {
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 2px;
    background-color: white;
    margin-top: 10px;
}
::v-deep .el-button-group .selBtn {
    background: #fff;
    border: 1px solid #0b7be3;
    color: #0b7be3;
}
::v-deep .el-button-group .unselBtn {
    background: #fff;
    border: 1px solid #ededf2;
    color: #666666;
}
.header-left {
    float: left;
    font-size: 14px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333333;
    line-height: 40px;
    display: flex;
    justify-content: center;
}
.header-right {
    float: right;
}
.container-header {
    float: left;
    width: 100%;
    border-bottom: 1px solid #ededf2;
    padding-left: 12px;
}
.container-table {
    float: left;
    margin-top: 6px;
    width: 100%;
    //   max-height: calc(100vh - 600px);
    overflow: auto;
}
.mb8 {
    float: left;
    margin-top: 6px;
    width: 100%;
    ::v-deep .el-form-item {
        margin-bottom: 0;
    }
}
.drawer-footer {
    display: flex;
    position: relative;
    z-index: 9999;
    bottom: -40px;
    height: 40px;
    justify-content: center;
    width: 100%;
}
.hign-line {
    position: relative;
    left: -8px;
    top: 14px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid #0b7be3;
    float: left;
}
.drawer-close {
    background: #f7f8fa;
    border-color: #f7f8fa;
}
.submit-footer {
    height: 52px;
    background: #ffffff;
    box-shadow: 0px -5px 5px 0px rgba(0, 0, 0, 0.08);
    border-radius: 4px 4px 0px 0px;
    position: fixed;
    z-index: 9;
    bottom: 0px;
    width: 100%;
    left: 0px;
    display: flex;
    justify-content: center;
    align-items: center;
}
.samplingPercent {
    position: absolute;
    z-index: 9;
    right: 20px;
}
::v-deep .el-card {
    padding-top: 0px;
}
.app-detail {
    max-height: calc(100vh - 180px);
    overflow: auto;
}
.result-tag-red {
    width: 36px;
    height: 18px;
    font-size: 12px;
    font-weight: 400;
    color: #eb5648;
    background: rgba(235, 86, 72, 0.08);
    line-height: 18px;
    border-radius: 2px;
}
.result-tag-green {
    width: 40px;
    height: 20px;
    font-size: 12px;
    font-weight: 400;
    color: #20b09f;
    line-height: 18px;
    background: rgba(32, 176, 159, 0.08);
    border-radius: 2px;
}
.size12 {
    font-size: 12px;
}
</style>
